package org.example.com.entity;

import org.example.com.annotation.MRPAnnotations;

import java.util.HashMap;
import java.util.Map;

/**
 * 库存
 */
//@MRPAnnotations.MRPEntity("库存")
//public class Inventory {
//    @MRPAnnotations.MRPField(description = "物料库存量")
//    private Map<Item, Integer> stock = new HashMap<>();
//
//    public void addStock(Item item, int quantity) {
//        stock.put(item, quantity);
//    }
//
//    public int getStock(Item item) {
//        return stock.getOrDefault(item, 0);
//    }
//}
public class Inventory {
    private Map<Item, Integer> stockLevels = new HashMap<>();

    public void addStock(Item item, int quantity) {
        stockLevels.put(item, quantity);
    }

    public int getCurrentStock(Item item) {
        return stockLevels.getOrDefault(item, 0);
    }

    public void reduceStock(Item item, int quantity) {
        int currentStock = getCurrentStock(item);
        if (currentStock >= quantity) {
            stockLevels.put(item, currentStock - quantity);
        } else {
            throw new IllegalArgumentException("库存不足");
        }
    }
}